package com.ef.util;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.ef.domain.LeadsClassEntity;

public class LeadsClassEntityExample extends CustomExample<LeadsClassEntity> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3481802116789877101L;
	protected static final org.apache.log4j.Logger log = org.apache.log4j.Logger
			.getLogger(LeadsClassEntityExample.class);

	public LeadsClassEntityExample(LeadsClassEntity entity,
			Class<LeadsClassEntity> entityClass) {
		super(entity, entityClass);

	}

	public LeadsClassEntityExample(LeadsClassEntity entity) {
		super(entity, NoVale);

	};

	/**
	 * ʵ��ͨ�ò�ѯ����, Ҫ��view���entity��set
	 */
	@Override
	public void appendCondition(Criteria criteria) {
		if (entity.getBookingUser() != null
				&& entity.getBookingUser().getName() != null
				&& entity.getBookingUser().getName().trim().length() > 0
				&& entity.getBookingUser().getId() != null) {
			criteria.createCriteria("bookingUser").add(
					Restrictions.eq("id", entity.getBookingUser().getId()));
		}
		if (entity.getCheckinUser() != null
				&& entity.getCheckinUser().getName() != null
				&& entity.getCheckinUser().getName().trim().length() > 0
				&& entity.getCheckinUser().getId() != null) {
			criteria.createCriteria("checkinUser").add(
					Restrictions.eq("id", entity.getCheckinUser().getId()));
		}
		if (entity.getCancelUser() != null
				&& entity.getCancelUser().getName() != null
				&& entity.getCancelUser().getName().trim().length() > 0
				&& entity.getCancelUser().getId() != null) {
			criteria.createCriteria("cancelUser").add(
					Restrictions.eq("id", entity.getCancelUser().getId()));
		}
		Criteria cLeads = criteria.createCriteria("leads", "leads");
		if (entity.getLeads() != null && entity.getLeads().getName() != null
				&& entity.getLeads().getName().trim().length() > 0
				&& entity.getLeads().getId() != null) {
			cLeads.add(Restrictions.eq("id", entity.getLeads().getId()));
		}
		if (entity.getLeads() != null && entity.getLeads().getCc() != null) {
			cLeads.createCriteria("cc").add(
					Restrictions.like("name", entity.getLeads().getCc()
							.getName().trim(), MatchMode.ANYWHERE));
		}
		// ���ʱ���ѯ
		this.appendBetweenDateProperty(criteria);
	}
}
